/**
 * 将a-z展开为abcdefg......z
 */

#include <stdio.h>
#include <ctype.h>

void expand(char s1[], char s2[]);

int main(void) {
    char s1[] = "as&-ldkfj2-9a-z__b-a";
    char s2[1000];
    printf("%s\n", s1);
    expand(s1, s2);
    printf("%s\n", s2);

    return 0;
}

void expand(char s1[], char s2[]) {
    int i, j;
    i = j = 0;
    while(s1[i]) {
        if (s1[i] == '-') {
            // 检测到数字
            if ((isdigit(s1[i-1]) && isdigit(s1[i+1])) || (isupper(s1[i-1]) && isupper(s1[i+1])) || (islower(s1[i-1]) && islower(s1[i+1]))) {
                for (int n = s1[i-1] + 1; n <= s1[i+1]; n++)
                    s2[j++] = n;
                i += 2;
            } else {
                s2[j++] = s1[i++];
            }
        } else {
            s2[j++] = s1[i++];
        }
    }
    s2[j] = '\0';
}
